<?php

declare(strict_types=1);

namespace Api\Service\v1\Work;

use App\CustHub\Model\ChChannelCode;

class ChannelCodeApiService
{
    public function getChannelCodeList(array $params): \Hyperf\Database\Model\Collection|array|\Hyperf\Collection\Collection
    {
        $name = $params['name'] ?? '';
        $limit = $params['limit'] ?? '';

        $list = ChChannelCode::query()
            ->select(['id','channel_name'])
            ->where('main_uid',$params['uid'])
            ->when($name,function ($query) use ($name){
                $query->where('channel_name','like',"%{$name}%");
            })
            ->when($limit,function ($query) use ($limit){
                $query->limit($limit);
            })
            ->orderBy('created_at','desc')
            ->get();

        return $list;
    }
}